import com.sun.xml.internal.fastinfoset.tools.XML_SAX_StAX_FI;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-10
 * Time: 8:23
 */
//Arrays的一些方法的应用+static成员+代码块+内部类
public class TestDemo {
    {
    //实例化代码块
    }
    static {
    //静态代码块
    }
    public static void main(String[] args) {
        {
        //  普通代码块
        }
        //填充
        int[] array = new int[10];
        //Arrays.fill(array,99);
        Arrays.fill(array,2,5,99);
        System.out.println(Arrays.toString(array));
    }
    public static void main10(String[] args) {
        int[] array = {1,2,3,13,4,5};
        Arrays.sort(array);
        int ret = Arrays.binarySearch(array,3);
        System.out.println(ret);
    }
    public static void main9(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = array.clone();
        System.out.println(Arrays.toString(array));
        System.out.println("========================");
        System.out.println(Arrays.toString(copy));
    }
    //Object 可以接受任意类型  他是一个祖先类
    public static void main8(String[] args) {
        int[] array = {1,2,3,4,5};
        int[] copy = new int[array.length];
        System.arraycopy(array,2,copy,0,array.length-2);
        System.out.println(Arrays.toString(array));
        System.out.println("========================");
        System.out.println(Arrays.toString(copy));
    }
    public static void main7(String[] args) {
        int[] array = {1,2,3,4,5};
//        int[] copy = Arrays.copyOf(array,array.length);
        int[] copy = Arrays.copyOfRange(array,1,3);
        System.out.println(Arrays.toString(array));
        System.out.println("========================");
        System.out.println(Arrays.toString(copy));
    }
    public static void main6(String[] args) {
        int[][] array = new int[2][];
        array[0] = new int[3];
        array[1] = new int[5];
        System.out.println(Arrays.deepToString(array));

    }
    public static void main5(String[] args) {
        int[][] array1 = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[2][];
        int[][] array3 = new int[][]{{1,2,3},{4,5,6}};

        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j < array1[i].length; j++) {
                System.out.print(array1[i][j]+" ");
            }
        }
        System.out.println();
        for (int[] tmp:array1) {
            for (int x:tmp) {
                System.out.print(x+" ");
            }
        }
        System.out.println();
        System.out.println(Arrays.deepToString(array2));
    }
    public static void main4(String[] args) {
        int[] array = {1,2,3,4};
        System.out.println(array[10]);
    }
    public static void main3(String[] args) {
        int[] array = null;
        System.out.println(array[0]);
    }
    public static void test1(int[] array){
        System.out.println(array.length);
    }
    public static void main2(String[] args) {
        int[] array = null;
        test1(array);
    }
    public static int maxSubArray(int[] nums) {
        int max = nums[0];
        int add = 0;
        for(int i = 0;i < nums.length;i++){
            add += nums[i];
            if(add >= 0){
                if(add > max){
                    max = add;
                }
            }else{
                if(add > max){
                    max = add;
                }
                add = 0;
            }
        }
        return max;
    }
    public static void main1(String[] args) {
        int[] array = {-2,1,-3,4,-1,2,1,-5,4};
        int ret = maxSubArray(array);
        System.out.println(ret);
    }
}
